package com.juneyao.bigdata.service.impl;

import com.juneyao.bigdata.domain.*;
import com.juneyao.bigdata.service.ElasticSearchService;
import com.juneyao.bigdata.service.HbaseSearchService;
import com.juneyao.bigdata.service.UserInteractiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;

/**
 * @author quanbiao
 * @date 2018-06-28
 * 用户精准营销实现
 */
@Service("userInteractiveService")
public class UserInteractiveServiceImpl implements UserInteractiveService{

    private Logger logger = LoggerFactory.getLogger("UserInteractiveServiceImpl");

    @Autowired
    private ElasticSearchService elasticSearchService;

    @Autowired
    private HbaseSearchService hbaseSearchService;

    /**
     * 根据集合，分页查询用户详细信息
     *
     * @param groupPeopleVO
     * @return
     */
    @Override
    public ResultData queryUserDetailForPage(GroupPeopleVO groupPeopleVO) {
        ResultData resultData = new ResultData();
        //分页获取用户id
        PageValueCount pageValueCount = elasticSearchService.queryUserIdsForPage(groupPeopleVO);
        //Hbase查询用户详细细信息
        List<HashMap<String, String>> userDetailMap = hbaseSearchService.userDetailForShow(pageValueCount.getUserIds(), groupPeopleVO.getLabelId());
        //用户详细信息
        resultData.setData(userDetailMap);
        //总记录数,因为只显示10万条，所以设置count最多10万
//        resultData.setCount(pageValueCount.getCount() >= 100000 ? 100000 : pageValueCount.getCount());
        resultData.setCount(pageValueCount.getCount());
        resultData.setErrorCode(0);
        resultData.setMsg("成功");
        logger.info("success!!!");
        return resultData;
    }

    /**
     * 获取集合人数
     * @param peopleGroupId
     * @return
     */
    @Override
    public PeopleGroup peopleGroupSum(PeopleGroupId peopleGroupId) {
        //返回集合人数
        PeopleGroup peopleGroup = elasticSearchService.peopleGroupSum(peopleGroupId);
        return peopleGroup;
    }
}
